<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 作者：一世长安_
        // 链接：https://www.nowcoder.com/discuss/925753
        // 来源：牛客网

        //输入：[['A', 'B'], ['a', 'b'], ['1', '2']];
        //输出：['Aa1','Aa2','Ab1','Ab2','Ba1','Ba2','Bb1','Bb2']

        function pailie(arr) {
            let res = []
            const dfs = (path, index) => {
                console.log('path',path);
                console.log('index',index);
                if (path.length == arr.length) {
                    res.push(path)
                    return
                }
                arr.forEach((n, i) => {
                    console.log('arr',n);
                    n.forEach(k => {
                        console.log('i',i);
                        if (i == index) {
                            dfs(path + k, index + 1)
                        }
                    })
                })
            }
            dfs("", 0)
            return res
        }
        let arr=[['A', 'B'], ['a', 'b'], ['1', '2']];
        let res=pailie(arr);
        console.log(res);
    </script>
</body>

</html>